/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.inmp.opconf;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author wangyazhou
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2013-5-20 下午4:16:28          wangyazhou        1.0         To create
 * </p>
 *
 * @since  
 * @see     
 */
public class OpConfManager {

    private static final Logger logger = Logger.getLogger(OpConfManager.class);

    private static OpConfManager instance = new OpConfManager();

    private List<String[]> resTypeList = new ArrayList<String[]>();

    private Map<Long, String> nwPortMap = new ConcurrentHashMap<Long, String>();

    private OpConfManager() {
        resTypeList();
    }

    /**
     * 
     * @return
     */
    public static OpConfManager getInstance() {
        return instance;
    }

    /**
     * 获取网络设备与其子资源的类 ID
     */
    @SuppressWarnings("unchecked")
    public void resTypeList() {
        SAXReader reader = new SAXReader();
        Document doc = null;

        try {
            doc = reader.read("inmp-conf/opmanager.xml");
            List<Element> elements = doc.selectNodes("/confList/typeList/type");
            for (Element e : elements) {
                String[] strAry = new String[6];
                strAry[0] = e.attributeValue("kpiname").trim();
                strAry[1] = e.attributeValue("typeId").trim();
                strAry[2] = e.attributeValue("name").trim();
                strAry[3] = e.elementText("port").trim();
                resTypeList.add(strAry);

                nwPortMap.put(Long.parseLong(strAry[1]), strAry[3]);
            }
            //            List<Element> eventTypes = doc.selectNodes("/confList/eventList/type");
            //            for (Element e : eventTypes) {
            //                String name = e.attributeValue("name").trim();
            //                Long type = Long.parseLong(e.attributeValue("id").trim());
            //
            //            }
        } catch (Exception e) {
            logger.error(e);
        }
    }

    public List<String[]> getResTypeList() {
        return resTypeList;
    }

    public String getPortType(Long rssType) {
        return "";
    }

    public Map<Long, String> getNwPortMap() {
        return nwPortMap;
    }

}
